<?php
if(!tep_session_is_registered('sppc_customer_group_id')) { 
  $customer_group_id = '0';
  } else {
   $customer_group_id = $sppc_customer_group_id;
  }
				// calculate the previous and next
                if (isset($_REQUEST['manufacturers_id'])) { 
               $products_ids = tep_db_query("select p.products_id from " . TABLE_PRODUCTS . " p where p.products_status = '1'  and p.manufacturers_id = '" . (int)$_REQUEST['manufacturers_id'] . "'and find_in_set('".$customer_group_id."', products_hide_from_groups) = 0");
				$category_name_query = tep_db_query("select manufacturers_name from " . TABLE_MANUFACTURERS . " where manufacturers_id = '" . (int)$_REQUEST['manufacturers_id'] . "'");
				$category_name_row = tep_db_fetch_array($category_name_query);
				$prev_next_in = PREV_NEXT_MB . ' <u><b><font size="1" color="#ff0000">' . ($category_name_row['manufacturers_name']) . '<u></b></font>';
				$fPath = 'manufacturers_id=' . (int)$_REQUEST['manufacturers_id'];
                } else {
				if (!$current_category_id) {
					$catID_query = tep_db_query ("SELECT categories_id FROM " . TABLE_PRODUCTS_TO_CATEGORIES . " WHERE products_id ='" .  (int)$_REQUEST['products_id'] . "'");
					$catID_row = tep_db_fetch_array($catID_query);
					$current_category_id = $catID_row['categories_id'];
				}
				$products_ids = tep_db_query("select p.products_id from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_TO_CATEGORIES . " ptc where p.products_status = '1'  and p.products_id = ptc.products_id and ptc.categories_id = $current_category_id and find_in_set('".$customer_group_id."', products_hide_from_groups) = 0");
				$category_name_query = tep_db_query("select categories_name from " . TABLE_CATEGORIES_DESCRIPTION . " where categories_id = $current_category_id AND language_id = $languages_id");
				$category_name_row = tep_db_fetch_array($category_name_query);
				$prev_next_in = PREV_NEXT_CAT . ' <u><b><font size="1" color="#ff0000">' . ($category_name_row['categories_name']) . '<u></b></font>';
				$fPath = 'catID=' . $catID;
				}
				while ($product_row = tep_db_fetch_array($products_ids)) {
					$id_array[] = $product_row['products_id'];
				}
				reset ($id_array);
				$counter = 0;
				while (list($key, $value) = each ($id_array)) {
					if ($value == (int)$_REQUEST['products_id']) {
						$position = $counter;
						if ($key == 0)
							$previous = -1; // it was the first to be found
						else
							$previous = $id_array[$key - 1];

						if ($id_array[$key + 1])
							$next_item = $id_array[$key + 1];
						else {
							$next_item = $id_array[0];
						}
					}
					$last = $value;
					$counter++;
				}
				if ($previous == -1)
					$previous = $last;
?>
<tr>
  <td>
    <table border="0" align="center" width="100%">
      <tr>
        <td align="left" class="main" nowrap><a href="<?php echo tep_href_link(FILENAME_PRODUCT_INFO, "$fPath&products_id=$previous"); ?>"><?php echo tep_image_button('button_prev.gif', TEXT_PREVIOUS); ?></a></td>
        <td align="center" class="main" valign="center" nowrap><?php echo (PREV_NEXT_PRODUCT) . '&nbsp;<b><u>' . ($position+1 . "</u></b> " . PREV_NEXT_OF . " <b>" . $counter) . '</b> ' . $prev_next_in; ?></td>
        <td align="right" class="main" nowrap><a href="<?php echo tep_href_link(FILENAME_PRODUCT_INFO, "$fPath&products_id=$next_item"); ?>"><?php echo tep_image_button('button_next.gif', TEXT_NEXT); ?></a></td>
      </tr>
    </table>
  </td>
</tr>
